package oojo.data.spec;

import java.util.Set;
import java.util.LinkedHashSet;
import java.util.Collections;


import oojo.data.Query;

/**
 * Find an entity by id.
 */
public class FindById<E> implements Query<E, E> {

    private Object id;
    private Set<String> joins;
    
    public FindById() {}
    
    public FindById(Object id, String... joins) {
        setId(id);
        Collections.addAll(getJoins(), joins);
    }
    
    /**
     * The id that will be matched.
     */
    public Object getId() {
        return id;
    }
    
    public void setId(Object id) {
        this.id = id;
    }
    
    /**
     * The relations that should be initialized.
     */
    public Set<String> getJoins() {
        if (joins == null) {
            joins = new LinkedHashSet<String>();
        }
        
        return joins;
    }
    
    public void setJoins(Set<String> joins) {
        this.joins = joins;
    }
}
